package com.desmao.service.impl;

import com.github.pagehelper.PageInfo;
import com.desmao.mapper.BaseMapper;
import com.desmao.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * @Author: denghp
 * @Date: 17-1-5
 * @Time: 下午5:19
 * @Description:
 * @Version \$versionId$
 */
@Service("baseService")
public class BaseServiceImpl<T, ID extends Serializable> implements BaseService<T, ID> {

    @Autowired
    private BaseMapper<T,ID> baseMapper;

    @Override
    public int insert(T entity) {
        if (StringUtils.isEmpty(entity)) {
            return 0;
        }
        return baseMapper.insert(entity);
    }

    @Override
    public int insertSelective(T entity) {
        if (StringUtils.isEmpty(entity)) {
            return 0;
        }
        return baseMapper.insertSelective(entity);
    }

    @Override
    public T selectByPrimaryKey(ID id) {
        if (StringUtils.isEmpty(id)) {
            return null;
        }
        return baseMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKey(T record) {
        if (StringUtils.isEmpty(record)) {
            return 0;
        }
        return baseMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKeySelective(T record) {
        if (StringUtils.isEmpty(record)) {
            return 0;
        }
        return baseMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int deleteByPrimaryKey(ID id) {
        if (StringUtils.isEmpty(id)) {
            return 0;
        }
        return baseMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<T> selectList(Map<String, Object> condition, String orderBy) {
        return baseMapper.selectList(condition, orderBy);
    }

    @Override
    public List<T> selectList() {
        return baseMapper.selectList();
    }

    @Override
    public PageInfo<T> selectPage(int page, int rows) {
        return baseMapper.selectPage(page, rows);
    }

    @Override
    public PageInfo<T> selectPage(Map<String, Object> condition, int page, int rows, String orderBy) {
        return baseMapper.selectPage(condition, page, rows, orderBy);
    }
}
